package com.erp.controller;

import com.erp.annotation.Permission;
import com.erp.pojo.SellJh;
import com.erp.service.SellJhService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;
@RestController
@CrossOrigin
public class SellJhController {
    //注入service
    @Autowired
    private SellJhService sellJhService;

    /*处理客户开发过程记录的添加请求*/
    @PostMapping("/saveSellJh")
    public Map<String,Object> saveSellJh(@RequestBody SellJh sellJh){
        Map<String,Object> result=new HashMap<>();
        result.put("code",400);
        result.put("msg","操作失败.....");
        try{
            sellJhService.save(sellJh);
            result.put("code",200);
            result.put("msg","添加开发销售过程成功......");
        }catch(Exception ex){
            ex.printStackTrace();
        }
        return result;
    }

    /*处理销售过程分页查询请求*/
    @GetMapping("/sellJhList")
    public Map<String,Object> sellJhList(@RequestParam(defaultValue = "1") Integer pageNum
        ,@RequestParam(defaultValue = "3") Integer pageSize){
        return sellJhService.querySellJhListService(pageNum,pageSize);
    }


    /*处理客户销售渠道数据更新请求*/
    @PostMapping("/updateSellJh")
    public Map<String,Object> updateSellJh(@RequestBody SellJh sellJh){

        Map<String,Object> result=new HashMap<>();
        result.put("code",400);
        result.put("msg","操作失败......");
        try{
            sellJhService.updateById(sellJh);
            result.put("code",200);
            result.put("msg","更新客户销售过程数据成功.........");
        }catch (Exception ex){
            ex.printStackTrace();
        }

        return result;
    }


    /*处理客户销售信息删除请求*/
    @GetMapping("/delSellJh")
    public Map<String,Object> delSellJh(Integer id){

        Map<String,Object> result=new HashMap<>();
        result.put("code",400);
        result.put("msg","操作失败......");
        try{
            sellJhService.removeById(id);
            result.put("code",200);
            result.put("msg","删除客户销售过程数据成功.........");
        }catch (Exception ex){
            ex.printStackTrace();
        }

        return result;
    }
}
